<?php
/**
 * Created by PhpStorm.
 * User: 华为
 * Date: 2018/11/16
 * Time: 18:10
 */
 header("content-type:text/html;charset=utf-8");
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,"http://top.17k.com/top/top100/06_vipclick/06_vipclick_serialWithLong_top_100_pc.html");
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$res = curl_exec($ch);
//var_dump($res);
$preg = '#<td width="30">(.*)</td><td width="60"><a href=".*" target="_blank">(.*)</a></td><td><a class="red" href=".*" title=".*" target="_blank">(.*)</a></td><td><a href=".*" title=".*" target="_blank">(.*)</a></td><td>(.*)</td><td><a href=".*" title=".*" target="_blank">(.*)</a></td><td width="30">(.*)</td><td>(.*)</td></tr>#iUs';
preg_match_all($preg,$res,$value);


$pai = $value[1];
$type = $value[2];
$name = $value[3];
$zui = $value[4];
$geng = $value[5];
$author = $value[6];
$zhuang = $value[7];
$bang = $value[8];
//var_dump($pai);
//$pdo = new PDO("mysql:dbname=1608b;host=127.0.0.1","root","root");
//for($i=0;$i<100;$i++){
////$res = $pdo->exec
//$sql = "insert into `book` ('pai','type','name','zui','geng','author','zhuang','bang') VALUES ('$pai[$i]','$type[$i]','$name[$i]','$zui[$i]','$geng[$i]','$author[$i]','$zhuang[$i]','$bang[$i]')";
//}
//var_dump();
$pdo = new PDO("mysql:host=127.0.0.1;dbname=1608b","root","root");
for($i=0;$i<100;$i++){
    $res = $pdo->exec("insert into `book` values (null,'$pai[$i]','$type[$i]','$name[$i]','$zui[$i]','$geng[$i]','$author[$i]','$zhuang[$i]','$bang[$i]')");
}
echo "<pre>";
var_dump($res);
